package com.ruoyi.training.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.A03ResSupport;
import com.ruoyi.training.service.IA03ResSupportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 供应商库Controller
 * 
 * @author WorrilessGo
 * @date 2025-11-18
 */
@RestController
@RequestMapping("/support")
public class A03ResSupportController extends BaseController
{
    @Autowired
    private IA03ResSupportService a03ResSupportService;

    /**
     * 查询供应商库列表
     */
    @RequiresPermissions("training:support:list")
    @GetMapping("/list")
    public TableDataInfo list(A03ResSupport a03ResSupport)
    {
        startPage();
        List<A03ResSupport> list = a03ResSupportService.selectA03ResSupportList(a03ResSupport);
        return getDataTable(list);
    }

    /**
     * 导出供应商库列表
     */
    @RequiresPermissions("training:support:export")
    @Log(title = "供应商库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, A03ResSupport a03ResSupport)
    {
        List<A03ResSupport> list = a03ResSupportService.selectA03ResSupportList(a03ResSupport);
        ExcelUtil<A03ResSupport> util = new ExcelUtil<A03ResSupport>(A03ResSupport.class);
        util.exportExcel(response, list, "供应商库数据");
    }

    @PostMapping("/exportModel")
    public void exportModel(HttpServletResponse response)
    {
        List<A03ResSupport> list = new ArrayList<>();
        ExcelUtil<A03ResSupport> util = new ExcelUtil<A03ResSupport>(A03ResSupport.class);
        util.exportExcel(response, list, "供应商库数据");
    }

    /**
     * 导入供应商库列表
     */
    @RequiresPermissions("training:support:import")
    @Log(title = "供应商库", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception{
        ExcelUtil<A03ResSupport> util = new ExcelUtil<A03ResSupport>(A03ResSupport.class);
        List<A03ResSupport> a03ResSupports = util.importExcel(file.getInputStream(), 1);
        int result = a03ResSupportService.batchInsertA03ResSupport(a03ResSupports);
        return toAjax(result);
    }


    /**
     * 获取供应商库详细信息
     */
    @RequiresPermissions("training:support:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(a03ResSupportService.selectA03ResSupportById(id));
    }

    /**
     * 新增供应商库
     */
    @RequiresPermissions("training:support:add")
    @Log(title = "供应商库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody A03ResSupport a03ResSupport)
    {
        return toAjax(a03ResSupportService.insertA03ResSupport(a03ResSupport));
    }

    /**
     * 修改供应商库
     */
    @RequiresPermissions("training:support:edit")
    @Log(title = "供应商库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody A03ResSupport a03ResSupport)
    {
        return toAjax(a03ResSupportService.updateA03ResSupport(a03ResSupport));
    }

    /**
     * 删除供应商库
     */
    @RequiresPermissions("training:support:remove")
    @Log(title = "供应商库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(a03ResSupportService.deleteA03ResSupportByIds(ids));
    }
}
